<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_线下订单管理</title>
	<script type="text/javascript">
		var datatable_content;
		var formParam ;
		function onQuery() {
			$("#queryForm").submit();
		}
		
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/ulorder/queryUlorder',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": "customer.customerName"},
	             	 {"mData": "warehouse.groupName"},
	             	 {"mData": "orderno"},
	             	 {"mData": "expNo"},
	             	 {"mData": "creater.realname"},
	             	 {"mData": "createTime"},
	             	 {"mData": null},
	             	 {"mData": "sendTime"},
	             	 {"mData": null},
	             	 {"mData": null},
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [6],
		              "mRender": function (data, display, row) {
			        	 return new Date(data.time).Format("yyyy-MM-dd hh:mm:ss");
			           }
		            },
	             	{"aTargets": [7],
		              "mRender": function (data, display, row) {
			        	 return row.sender ? row.sender.realname : "";
			           }
		            },
	             	{"aTargets": [9],
		              "mRender": function (data, display, row) {
			        	 return row.status == "login" ? "<font color=red>已登记</font>" :
			        	 		row.status == "send" ? "<font color=green>已发货</font>" : row.status == "cancel" ? "<font color=green>已取消</font>":"";
			           }
		            },
	             	{"aTargets": [10],
		              "mRender": function (data, display, row) {
			        	 return "<a href=\"${ctx}/ulorder/toUlorderDetail/"+row.orderno+"\"  class=\"btn btn-primary\" >明细</a>";
			           }
		            },
	             ],
			});
		}
		function callback(sSource, aoData, fnCallback ) {
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
        $(function() {
		    $("#queryForm").validate(); 
		    $("#inputForm").validate(); //为inputForm注册validate函数
			$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
			initTable();
			formParam = $("#queryForm").serializeArray();
       });
	  
		//取消单重发
		function recall(orderno){
		    $("btn_"+orderno).attr("disabled", true);
		    $.ajax({
			type:'post',
			url:'${ctx}/cancelOrder/ajaxRecall',
			data:{
				orderno:orderno
			},
			dataType:'json',
			success:function(data) {
			    var msg=data.msg;
			    
			    if(msg=='success'){
			       alert("重发操作成功。");
			       $("#queryForm").submit();
			    }else if(msg=='noExist'){
			       alert("不存在此单号");
			       $("btn_"+orderno).attr("disabled", false);
			    }else if(msg=='noCancelStatus'){
			       alert("不在取消状态，不能重发");
			       $("btn_"+orderno).attr("disabled", false);
			    }else{
			       alert("网络繁忙，请稍后重试...");
			       $("btn_"+orderno).attr("disabled", false);
			    }
			    
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				$("btn_"+orderno).attr("disabled", true);
			}
	   });
	   
	}
	  
    </script>
</head>

<body>
<section class="content">
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form class="form-search" id="queryForm" action="${ctx}/ulorder/v2_toUlorderMgrPage" method="post">
			<div class="form-group row">	
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
			    <label class="input-group-text">商家名称:</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="form-control required" onchange="ajaxAreaGroup(this,'_warehouseCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">作业仓库:</label>
				 <select  name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  class="form-control">
					<option value=""></option>
					<c:forEach items="${warehouseList}" var="w" >
					   <option value="${w.groupCode}" 
					   <c:if test="${param._warehouseCode eq w.groupCode }">selected=selected</c:if>
					   >${w.groupName}</option>
				   </c:forEach>
				</select>
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">订单状态:</label>
				 <select  name="_status"  id="_status"  class="form-control">
					<option value="" <c:if test="${param._status eq ''}">selected="selected"</c:if>></option>
				    <option value="login" <c:if test="${param._status eq 'login'}">selected="selected"</c:if> >已登记</option>
				    <option value="send"  <c:if test="${param._status eq 'send'}" >selected="selected"</c:if> >已发货</option>
				</select>
				</div>
				</div>
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">单号:</label>
				<input type="text" id="_allOrderno" name="_allOrderno"  class="form-control" value="${param._allOrderno}"/>
				</div>
				</div>
				</div>  
				<div class="form-group row">
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">登记时间:</label> 
			 	<input type="text" name="_fromDate" id="_fromDate"  class="form-control" value="${param._fromDate}" /> 
			 	</div>
			 	</div>
			 	<div class="col-sm-3">
				<div class="input-group col-sm-12">
			 	<label class="input-group-text">至</label> 
			 	<input type="text" name="_toDate" id="_toDate" class="form-control" value="${param._toDate}"/> 
			 	</div>
			 	</div>
			 	<div class="col-sm-3">
				<div class="input-group col-sm-12">
			    <button type="submit" class="btn btn-info">搜索</button>
			    <a href="${ctx}/ulorder/toUlorderPage" class="btn btn-primary" >登记线下订单</a>
			    </div>
			    </div>
			    </div>
		    </form>
	   
</div>
</div>
</div>
</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>商家名称</th>
			    <th>作业仓库</th>
			    <th>能容订单号</th>
			    <th>快递单号</th>
			    <th>登记人</th>
			    <th>登记时间</th>
			    <th>发货人</th>
			    <th>发货时间</th>
			    <th>处理状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
</section>	
</body>
</html>
